var dates="LOL";

function testjs(){
	if(document.getElementById("username").value==""){
		alert("You must enter a username before chatting");
		return false;
	}
	else{
	var ip=getIpAddress();
	var today=getDate();
	var old=document.getElementById("mainchat").innerHTML;
	var entered=document.getElementById("chatb").value+"<br/>";
	var username=document.getElementById("username").value;
	document.title=username+" >> "+entered;
	var news="<b>("+today+")</b> <font color='blue'> "+username+"</font> >> "+entered+old;
	document.getElementById("mainchat").innerHTML=news;
	document.getElementById("chatb").value="";
	var url="InsertChat?sender="+username+"&ipaddress="+ip+"&timestamp="+today+"&message="+entered;
	var request=createRequest();
	request.open("GET",url,true);
	request.onreadystatechange=function(){
		if(request.readyState==4){
			if(request.status==200){
				//Do Nothing
			}
		}
	}
	request.send(null);
	}	
	
}

function createRequest(){
	var request=null;
	try{
		request=new XMLHttpRequest();
	}catch(tryMS){
		try{
			request=new ActiveXObject("Msxml2.XMLHTTP");
		}catch(otherMS){
			try{
				request=new ActiveXObject("Microsoft.XMLHTTP");
			}catch(failed){
				request=null;
			}
		}
	}
	return request;
}
function getDate(){
	var request=createRequest();
	var url="GetDate";
	request.open("GET",url,false);	
	request.send(null);
	request.onreadystatechange= function(){
		if(request.readyState==4){
			if(request.status==200){
				dates=request.responseText;
				return dates;
			}
		}		
	}
	return request.onreadystatechange();
}
function getIpAddress(){
	var ip;
	var request=createRequest();
	var url="GetIpAddress";
	request.open("GET",url,false);	
	request.send(null);
	request.onreadystatechange=function(){
		if(request.readyState==4){
			if(request.status==200){
				ip=request.responseText;
				return(ip);
				
			}
		}
	}	
	return request.onreadystatechange();
}
function boldme(){
	var en="<b>"+document.getElementById("chatb").value+"</b>";
	document.getElementById("chatb").value=en;	
}
function italicsme(){
	var en="<i>"+document.getElementById("chatb").value+"</i>";
	document.getElementById("chatb").value=en;	

}
function colorme(){
	var color=document.getElementById("fcolor").value;
	var en="<font color=\""+color+"\">"+document.getElementById("chatb").value+"</font>";
	document.getElementById("chatb").value=en;	

}

function refreshChat(){
	var message;
	var request=createRequest();
	var url="RefreshChat";
	request.open("GET",url,true);
	request.onreadystatechange=function(){
		if(request.readyState==4){
			if(request.status==200){
				message=request.responseText;
				document.getElementById("mainchat").innerHTML=message;
			}
		}
	}
	request.send(null);	
}
